package com.example.heimashop.utils;

import android.content.Context;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.example.heimashop.R;

/**
 * Glide图片加载工具类
 */
public class GlideUtils {

    private static RequestOptions defaultOptions = new RequestOptions()
            .placeholder(R.mipmap.ic_launcher)
            .error(R.mipmap.ic_launcher)
            .diskCacheStrategy(DiskCacheStrategy.ALL);

    /**
     * 加载图片
     */
    public static void loadImage(Context context, String url, ImageView imageView) {
        Glide.with(context)
                .load(url)
                .apply(defaultOptions)
                .into(imageView);
    }

    /**
     * 加载圆形图片
     */
    public static void loadCircleImage(Context context, String url, ImageView imageView) {
        Glide.with(context)
                .load(url)
                .apply(defaultOptions)
                .circleCrop()
                .into(imageView);
    }

    /**
     * 加载圆角图片
     */
    public static void loadRoundImage(Context context, String url, ImageView imageView, int radius) {
        Glide.with(context)
                .load(url)
                .apply(defaultOptions)
                .into(imageView);
    }
}
